home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / vol7n9.arc / WRITE.PAS < prev   
Pascal/Delphi Source File  |  1988-04-08  |  2KB  |  69 lines

  1. {$R+}
  2. PROGRAM Make_Write;
  3. TYPE
  4.   String255 = STRING[255];
  5. CONST
  6.   LastCol = 40; 
  7.   SQuote = #39; {single quote character}
  8. VAR
  9.   InfileName, OutfileName   : STRING[66];
  10.   before, after, line, part : String255;
  11.   InFile, OutFile           : Text;
  12.   Pos                       : Byte;
  13.  
  14.   FUNCTION InsertSQuotes(L : String255) : String255;
  15.   VAR Pos : Byte;
  16.   BEGIN
  17.     FOR Pos := Length(L) DOWNTO 1 DO
  18.       IF L[Pos] = SQuote THEN
  19.         Insert(SQuote, L, Pos);
  20.     InsertSQuotes := L;
  21.   END;
  22.  
  23. BEGIN
  24.   Write('  This program takes any standard ASCII ');
  25.   WriteLn('text file and converts it into a');
  26.   Write('  series of WriteLn statements for use i');
  27.   WriteLn('n your program.  It''s smart enough');
  28.   Write('  to double any single quote characters.');
  29.   WriteLn('  You can set the maximum length of');
  30.   Write('  lines to be printed, which allows you ');
  31.   WriteLn('to format the text of your program');
  32.   Write('  as you please.  The text you are readi');
  33.   WriteLn('ng was processed by the program.');
  34.   WriteLn;
  35.   WriteLn;
  36.   Write('Input file name  : ');
  37.   ReadLn(InfileName);
  38.   Write('Output file name : ');
  39.   ReadLn(OutfileName);
  40.   Assign(InFile, InfileName);
  41.   {$I-} Reset(InFile);        {$I+}
  42.   IF IOResult <> 0 THEN
  43.     BEGIN
  44.       WriteLn(#7, 'FILE ', InfileName, ' does not exist!');
  45.       Halt;
  46.     END;
  47.   Assign(OutFile, OutfileName);
  48.   {$I-} Rewrite(OutFile);     {$I+}
  49.   IF IOResult <> 0 THEN
  50.     BEGIN
  51.       WriteLn(#7, 'ERROR opening ', OutfileName);      Halt;
  52.     END;
  53.   WHILE NOT EoF(InFile) DO
  54.     BEGIN
  55.       ReadLn(InFile, line);
  56.       WHILE Length(line) > LastCol DO
  57.         BEGIN
  58.           Write(OutFile, 'Write(',SQuote);
  59.           Write(OutFile, InsertSQuotes(Copy(line, 1, LastCol)));
  60.           WriteLn(OutFile, SQuote, ');');
  61.           Delete(line, 1, LastCol);
  62.         END;
  63.       Write(OutFile, 'WriteLn(', SQuote);
  64.       Write(OutFile, InsertSQuotes(line));
  65.       WriteLn(OutFile,  SQuote, ');');
  66.     END;
  67.   Close(InFile);
  68.   Close(OutFile);
  69. END.